package com.kaizzi.data.jdl.helper;

import com.kaizzi.data.common.utils.DateUtil;
import com.kaizzi.data.common.utils.JsonUtil;
import com.kaizzi.data.jdl.model.ExcelModel;
import com.kaizzi.data.jdl.model.Page15Model;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Kzen
 * @Description description
 * @date 2020/9/18
 */
@Component
public class PageData15 {

    public String getData(ExcelModel model){

        Page15 page15 = new Page15();

        List<Page15Model> page15s = model.getPage15s();
        List<TempPage15> list = new ArrayList<>();
        for (Page15Model pageModel : page15s) {
            TempPage15 tempPage15 = new TempPage15();
            tempPage15.setDate(pageModel.getDate());
            tempPage15.setActiveUsers(pageModel.getActiveUser());
            list.add(tempPage15);
        }
        page15.setDataPeriod(DateUtil.getFirstDay2LastSunday());
        page15.setBeens(list);

        return JsonUtil.serialize(page15);
    }

    @Data
    private static class Page15{
        private String title;
        private String dataPeriod;
        private List<TempPage15> beens;
    }

    @Data
    private static class TempPage15{
        private String date;
        private String activeUsers;
    }
}
